package cn.iocoder.yudao.hires.controller.admin;

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.hires.entity.ResumeTagsDO;
import cn.iocoder.yudao.hires.vo.ResumeTrainingRespVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;


import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import  cn.iocoder.yudao.hires.vo.*;
import cn.iocoder.yudao.hires.entity.ResumeTrainingDO;
import cn.iocoder.yudao.hires.service.ResumeTrainingService;

@Tag(name = "管理后台 - 简历-培训经历")
@RestController
@RequestMapping("/resume/training")
@Validated
public class ResumeTrainingController {

    @Resource
    private ResumeTrainingService trainingService;

    @PostMapping("/create")
    @Operation(summary = "创建简历-培训经历")
    @TenantIgnore
    //@PreAuthorize("@ss.hasPermission('resume:training:create')")
    public CommonResult<Integer> createTraining(@Valid @RequestBody ResumeTrainingSaveReqVO createReqVO) {
        return success(trainingService.createTraining(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新简历-培训经历")
    @TenantIgnore
    //@PreAuthorize("@ss.hasPermission('resume:training:update')")
    public CommonResult<Boolean> updateTraining(@Valid @RequestBody ResumeTrainingSaveReqVO updateReqVO) {
        trainingService.updateTraining(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除简历-培训经历")
    @TenantIgnore
    //@PreAuthorize("@ss.hasPermission('resume:training:delete')")
    public CommonResult<Boolean> deleteTraining(@RequestParam("id") Integer id) {
        trainingService.deleteTraining(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得简历-培训经历")
    @TenantIgnore
    //@PreAuthorize("@ss.hasPermission('resume:training:query')")
    public CommonResult<ResumeTrainingRespVO> getTraining(@RequestParam("id") Integer id) {
        ResumeTrainingDO training = trainingService.getTraining(id);
        return success(BeanUtils.toBean(training, ResumeTrainingRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得简历-培训经历分页")
    @TenantIgnore
    //@PreAuthorize("@ss.hasPermission('resume:training:query')")
    public CommonResult<PageResult<ResumeTrainingRespVO>> getTrainingPage(@Valid ResumeTrainingPageReqVO pageReqVO) {
        PageResult<ResumeTrainingDO> pageResult = trainingService.getTrainingPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResumeTrainingRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出简历-培训经历 Excel")
    //@PreAuthorize("@ss.hasPermission('resume:training:export')")
    @ApiAccessLog(operateType = EXPORT)
    @TenantIgnore
    public void exportTrainingExcel(@Valid ResumeTrainingPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResumeTrainingDO> list = trainingService.getTrainingPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "简历-培训经历.xls", "数据", ResumeTrainingRespVO.class,
                        BeanUtils.toBean(list, ResumeTrainingRespVO.class));
    }

}